home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 1 / Cream of the Crop 1.iso / COMM / PCCP038.ARJ / TERM.C < prev    next >
Text File  |  1992-07-10  |  17KB  |  809 lines

  1. /*    Copyright (C) 1992 Peter Edward Cann, all rights reserved.
  2.  */
  3.  
  4. #include<stdio.h>
  5. #include<bios.h>
  6. #include<dos.h>
  7. #include<fcntl.h>
  8. #include<graph.h>
  9. #include"emu.h"
  10. #include"color.h"
  11. #include"port.h"
  12.  
  13.  
  14. int locechop;
  15.  
  16. dispkbd(code)
  17.     unsigned short code;
  18.     {
  19.     int i;
  20.     long tstamp, tstamp1, dayofticksp;
  21.     unsigned char ccode, scode;
  22.     ccode=code&0xff;
  23.     scode=(code>>8)&0xff;
  24.     if(ccode)
  25.         {
  26.         while(!(inp(basereg+STATREG)&0x20));
  27.         if(locechop)
  28.             dispport(ccode);
  29.         outp(basereg, code);
  30.         }
  31.     else
  32.         if(!emu.keys[scode].len)
  33.             putch(0x07);
  34.         else
  35.             for(i=0;i<emu.keys[scode].len;i++)
  36.                 {
  37.                 while(!(inp(basereg+STATREG)&0x20));
  38.                 if(emu.keys[scode].nullpause_p&&!emu.keys[scode].chars[i])
  39.                     {
  40.                     _bios_timeofday(_TIME_GETCLOCK, &tstamp);
  41.                     dayofticksp=0;
  42.                     while(1)
  43.                         {
  44.                         if(_bios_timeofday(_TIME_GETCLOCK, &tstamp1))
  45.                             dayofticksp+=20*60*60*24;
  46.                         if(tstamp1+dayofticksp-tstamp>22)
  47.                             break;
  48.                         }
  49.                     }
  50.                 else if(emu.keys[scode].nullpause_p&&(emu.keys[scode].chars[i]==0xff))
  51.                     {
  52.                     _bios_timeofday(_TIME_GETCLOCK, &tstamp);
  53.                     outp(basereg+LCTLREG, lctl|0x40);
  54.                     dayofticksp=0;
  55.                     while(1)
  56.                         {
  57.                         if(_bios_timeofday(_TIME_GETCLOCK, &tstamp1))
  58.                             dayofticksp+=20*60*60*24;
  59.                         if(tstamp1+dayofticksp-tstamp>10)
  60.                             break;
  61.                         }
  62.                     outp(basereg+LCTLREG, lctl);
  63.                     }
  64.                 else
  65.                     {
  66.                     if(locechop)
  67.                         dispport(emu.keys[scode].chars[i]);
  68.                     outp(basereg, emu.keys[scode].chars[i]);
  69.                     }
  70.                 }
  71.     }
  72.  
  73. #define LISTSIZ 16
  74.  
  75. struct
  76.     {
  77.     short index;
  78.     short row;
  79.     char rowset;
  80.     short column;
  81.     char colset;
  82.     short list[LISTSIZ];
  83.     short listindex;
  84.     }
  85.     funcstor[NFUNCS];
  86.  
  87. clrfuncstor(seqn)
  88.     short seqn;
  89.     {
  90.     int i;
  91.     for(i=funcstor[seqn].listindex-1;i>=0;i--)
  92.         funcstor[seqn].list[i]=0;
  93.     funcstor[seqn].row=funcstor[seqn].column=funcstor[seqn].listindex=funcstor[seqn].index=funcstor[seqn].rowset=funcstor[seqn].colset=0;
  94.     }
  95.  
  96. int bold, faint, blink, inverse, bkcolor, fgcolor;
  97. struct videoconfig far *vconf;
  98.  
  99. atthndl()
  100.     {
  101.     int adds, workingbk, workingfg;
  102.     adds=0;
  103.     if(vconf->adapter!=_MDPA)
  104.         {
  105.         workingbk=bkcolor;
  106.         workingfg=fgcolor;
  107.         if(faint)
  108.             if(inverse)
  109.                 if(bkcolor==WHITE)
  110.                     workingbk=GRAY;
  111.                 else
  112.                     adds+=FAINTADD;
  113.             else
  114.                 if(fgcolor==WHITE)
  115.                     workingfg=GRAY;
  116.                 else
  117.                     adds+=FAINTADD;
  118.         else
  119.             if(bold)
  120.                 {
  121.                 if(bkcolor==WHITE)
  122.                     workingbk=BWHITE;
  123.                 if(fgcolor==WHITE)
  124.                     workingfg=BWHITE;
  125.                 }
  126.         if(blink)
  127.             adds+=BLINKADD;
  128.         if(inverse)
  129.             {
  130.             if(blink)
  131.                 _settextcolor(workingbk+BLINKADD);
  132.             else
  133.                 _settextcolor(workingbk);
  134.             if(faint)
  135.                 _setbkcolor((long)(workingfg+FAINTADD));
  136.             else
  137.                 _setbkcolor((long)workingfg);
  138.             }
  139.         else
  140.             {
  141.             _settextcolor(workingfg+adds);
  142.             _setbkcolor((long)workingbk);
  143.             }
  144.         }
  145.     else
  146.         {
  147.         workingbk=BLACK;
  148.         if(bold&&!inverse)
  149.             workingfg=M_UNDER;
  150.         else
  151.             if(inverse)
  152.                 workingfg=WHITE;
  153.             else
  154.                 workingfg=M_NORMAL;
  155.         if(faint)
  156.             adds+=FAINTADD;
  157.         if(blink)
  158.             adds+=BLINKADD;
  159.         if(inverse)
  160.             {
  161.             if(blink)
  162.                 _settextcolor(workingbk+BLINKADD);
  163.             else
  164.                 _settextcolor(workingbk);
  165.             _setbkcolor((long)workingfg);
  166.             }
  167.         else
  168.             {
  169.             _settextcolor(workingfg+adds);
  170.             _setbkcolor((long)workingbk);
  171.             }
  172.         }
  173.     }
  174.  
  175.  
  176. ansiatthndl(seqn)
  177.     short seqn;
  178.     {
  179.     int i, adds, workingbk, workingfg;
  180.     if(emu.funcs[seqn].func==ANSIATTRIB)
  181.         for(i=0;i<funcstor[seqn].listindex;i++)
  182.             switch(funcstor[seqn].list[i])
  183.                 {
  184.                 /*at the moment this is strictly ANSI subset*/
  185.                 case 0:
  186.                     bkcolor=BLACK;
  187.                     fgcolor=WHITE;
  188.                     bold=faint=blink=inverse=0;
  189.                     break;
  190.                 case 1:
  191.                     bold=1;
  192.                     break;
  193.                 case 2:
  194.                     faint=1;
  195.                     break;
  196.                 case 5:
  197.                 case 6:
  198.                     blink=1;
  199.                     break;
  200.                 case 7:
  201.                     inverse=1;
  202.                     break;
  203.                 case 8:
  204.                 case 30:
  205.                 case 40:
  206.                     fgcolor=bkcolor;
  207.                     break;
  208.                 case 31:
  209.                 case 41:
  210.                     fgcolor=RED;
  211.                     break;
  212.                 case 32:
  213.                 case 42:
  214.                     fgcolor=GREEN;
  215.                     break;    
  216.                 case 33:
  217.                 case 43:
  218.                     fgcolor=YELLOW;
  219.                     break;
  220.                 case 34:
  221.                 case 44:
  222.                     fgcolor=BLUE;
  223.                     break;
  224.                 case 35:
  225.                 case 45:
  226.                     fgcolor=MAGENTA;
  227.                     break;
  228.                 case 36:
  229.                 case 46:
  230.                     fgcolor=CYAN;
  231.                     break;
  232.                 case 37:
  233.                 case 47:
  234.                     fgcolor=WHITE;
  235.                     break;
  236.                 default:
  237.                     break;
  238.                 }
  239.     atthndl();
  240.     }
  241.  
  242. int wrap_p;
  243.  
  244. wrapctl()
  245.     {
  246.     if(wrap_p)
  247.         _wrapon(_GWRAPON);
  248.     else
  249.         _wrapon(_GWRAPOFF);
  250.     }
  251.  
  252. char fpname[256], dribpname[256];
  253.  
  254. updstatus()
  255.     {
  256.     struct rccoord posptr;
  257.     short tc;
  258.     long bc;
  259.     char str[80];
  260.     posptr=_gettextposition();
  261.     tc=_gettextcolor();
  262.     bc=_getbkcolor();
  263.     _settextwindow(1,1,1,80);
  264.     _settextposition(1,1);
  265.     _settextcolor(BLACK);
  266.     _setbkcolor((long)WHITE);
  267.     _wrapon(_GWRAPOFF);
  268.     sprintf(str, "Both Shifts to Exit COM%u %5u %c%c%c %22s %22s",
  269.         comnum+1, speed, databits, parity, stopbits, fpname, dribpname);
  270.     _outtext(str);
  271.     _settextwindow(2,1,25,80);
  272.     wrapctl();
  273.     _settextcolor(tc);
  274.     _setbkcolor(bc);
  275.     _settextposition(posptr.row, posptr.col);
  276.     }
  277.  
  278. int graphics;
  279.  
  280. showchar(c)
  281.     char c;
  282.     {
  283.     char str[2];
  284.     if(graphics)
  285.         if(emu.gchars[c])
  286.             c=emu.gchars[c];
  287.     str[0]=c;
  288.     str[1]='\0';
  289.     _outtext(str);
  290.     }
  291.  
  292. perffunc(seqn)
  293.     short seqn;
  294.     {
  295.     struct rccoord posptr;
  296.     int i;
  297.     switch(emu.funcs[seqn].func)
  298.         {
  299.         case CLEAR:
  300.             _clearscreen(_GCLEARSCREEN);
  301.             updstatus();
  302.             _settextposition(1,1);
  303.             break;
  304.         case HOME:
  305.             _settextposition(1,1);
  306.             break;
  307.         case CLREOL:
  308.             posptr=_gettextposition();
  309.             _wrapon(_GWRAPOFF);
  310.             for(i=posptr.col;i<=80;i++)
  311.                 _outtext(" ");
  312.             _settextposition(posptr.row, posptr.col);
  313.             wrapctl();
  314.             break;
  315.         case UP:
  316.             posptr=_gettextposition();
  317.             if(posptr.row>1)
  318.                 _settextposition(posptr.row-1, posptr.col);
  319.             break;
  320.         case DOWN:
  321.             posptr=_gettextposition();
  322.             if(posptr.row<24)
  323.                 _settextposition(posptr.row+1, posptr.col);
  324.             else
  325.                 {
  326.                 showchar('\n');
  327.                 _settextposition(posptr.row, posptr.col);
  328.                 }
  329.             break;
  330.         case LEFT:
  331.             posptr=_gettextposition();
  332.             if(posptr.col>1)
  333.                 _settextposition(posptr.row, posptr.col-1);
  334.             break;
  335.         case RIGHT:
  336.             posptr=_gettextposition();
  337.             if(posptr.col<80)
  338.                 _settextposition(posptr.row, posptr.col+1);
  339.             break;
  340.         case GOTO:
  341.             if(funcstor[seqn].row<1)
  342.                 funcstor[seqn].row=1;
  343.             if(funcstor[seqn].row>24)
  344.                 funcstor[seqn].row=24;
  345.             if(funcstor[seqn].column<1)
  346.                 funcstor[seqn].column=1;
  347.             if(funcstor[seqn].column>80)
  348.                 funcstor[seqn].row=80;
  349.             _settextposition((emu.tophi_p?25-funcstor[seqn].row:funcstor[seqn].row), funcstor[seqn].column);
  350.             break;
  351.         case NORMAL:
  352.             fgcolor=WHITE;
  353.             bkcolor=BLACK;
  354.             blink=faint=bold=inverse=0;
  355.             atthndl();
  356.             break;
  357.         case BLINK:
  358.             blink=1;
  359.             atthndl();
  360.             break;
  361.         case NOBLINK:
  362.             blink=0;
  363.             atthndl();
  364.             break;
  365.         case BOLD:
  366.             bold=1;
  367.             atthndl();
  368.             break;
  369.         case NOBOLD:
  370.             bold=0;
  371.             atthndl();
  372.             break;
  373.         case FAINT:
  374.             faint=1;
  375.             atthndl();
  376.             break;
  377.         case NOFAINT:
  378.             faint=0;
  379.             atthndl();
  380.             break;
  381.         case INVERSE:
  382.             inverse=1;
  383.             atthndl();
  384.             break;
  385.         case NOINVERSE:
  386.             inverse=0;
  387.             atthndl();
  388.             break;
  389.         case UPN:
  390.             posptr=_gettextposition();
  391.             if(posptr.row-funcstor[seqn].row<1)
  392.                 _settextposition(1, posptr.col);
  393.             else
  394.                 _settextposition(posptr.row-funcstor[seqn].row, posptr.col);
  395.             break;
  396.         case DOWNN:
  397.             posptr=_gettextposition();
  398.             if(posptr.row+funcstor[seqn].row>24)
  399.                 {
  400.                 _settextposition(24,1);
  401.                 for(i=25-(posptr.row+funcstor[seqn].row);i<0;++i)
  402.                     showchar('\n');
  403.                 _settextposition(24, posptr.col);
  404.                 }
  405.             else
  406.                 _settextposition(posptr.row+funcstor[seqn].row, posptr.col);
  407.             break;
  408.         case LEFTN:
  409.             posptr=_gettextposition();
  410.             if(posptr.col-funcstor[seqn].column<1)
  411.                 _settextposition(posptr.row, 1);
  412.             else
  413.                 _settextposition(posptr.row, posptr.col-funcstor[seqn].column);
  414.             break;
  415.         case RIGHTN:
  416.             posptr=_gettextposition();
  417.             if(posptr.col+funcstor[seqn].column>80)
  418.                 _settextposition(posptr.row, 80);
  419.             else
  420.                 _settextposition(posptr.row, posptr.col+funcstor[seqn].column);
  421.             break;
  422.         case ANSIATTRIB:
  423.             ansiatthndl(seqn);
  424.             break;
  425.         case WRAP:
  426.             wrap_p=1;
  427.             wrapctl();
  428.             break;
  429.         case NOWRAP:
  430.             wrap_p=0;
  431.             wrapctl();
  432.             break;
  433.         case GOTOLINE:
  434.             posptr=_gettextposition();
  435.             if(funcstor[seqn].row<1)
  436.                 funcstor[seqn].row=1;
  437.             if(funcstor[seqn].row>24)
  438.                 funcstor[seqn].row=24;
  439.             _settextposition(emu.tophi_p?25-funcstor[seqn].row:funcstor[seqn].row, posptr.col);
  440.             break;
  441.         case GOTOCOL:
  442.             posptr=_gettextposition();
  443.             if(funcstor[seqn].column<1)
  444.                 funcstor[seqn].column=1;
  445.             if(funcstor[seqn].column>80)
  446.                 funcstor[seqn].row=80;
  447.             _settextposition(posptr.row, funcstor[seqn].column);
  448.             break;
  449.         case WYSEATTR:
  450.             if(funcstor[seqn].row&0x02)
  451.                 blink=1;
  452.             else
  453.                 blink=0;
  454.             if(funcstor[seqn].row&0x04)
  455.                 inverse=1;
  456.             else
  457.                 inverse=0;
  458.             if(funcstor[seqn].row&0x08)
  459.                 bold=1;
  460.             else
  461.                 bold=0;
  462.             if(funcstor[seqn].row&0x40)
  463.                 faint=1;
  464.             else
  465.                 faint=0;
  466.             atthndl();
  467.             break;
  468.         case GRAPHCHAR:
  469.             showchar(emu.gchars[funcstor[seqn].row]);
  470.             break;
  471.         case BEGGRAPH:
  472.             graphics=1;
  473.             break;
  474.         case ENDGRAPH:
  475.             graphics=0;
  476.             break;
  477.         case TAB:
  478.             posptr=_gettextposition();
  479.             _settextposition(posptr.row, posptr.col+(8-((posptr.col-1)%8)));
  480.             break;
  481.         case BELL:
  482.             putch(7);
  483.             break;
  484.         case DTAB:
  485.             posptr=_gettextposition();
  486.             for(i=0;i<(8-((posptr.col-1)%8));++i)
  487.                 _outtext(" ");
  488.  
  489.         case CRLF:
  490.             showchar('\n');
  491.             break;
  492.         default:
  493.             break;
  494.         }
  495.     }
  496.  
  497. dispport(c)
  498.     unsigned char c;
  499.     {
  500.     int seqn, done, ok;
  501.     done=0;
  502.     ok=0;
  503.     for(seqn=0;seqn<NFUNCS;seqn++)
  504.         {
  505.         if(emu.funcs[seqn].codes[funcstor[seqn].index]&0xff00)
  506.             switch(emu.funcs[seqn].codes[funcstor[seqn].index])
  507.                 {
  508.                 case END:
  509.                     if(funcstor[seqn].index)
  510.                         {
  511.                         done=1;
  512.                         perffunc(seqn);
  513.                         }
  514.                     break;
  515.                 case BINCOL:
  516.                     funcstor[seqn].column=c-emu.bincoloff;
  517.                     ok=1;
  518.                     if(emu.funcs[seqn].codes[++funcstor[seqn].index]==END)
  519.                         {
  520.                         done=1;
  521.                         perffunc(seqn);
  522.                         }
  523.                     break;
  524.                 case BINROW:
  525.                     funcstor[seqn].row=c-emu.binrowoff;
  526.                     ok=1;
  527.                     if(emu.funcs[seqn].codes[++funcstor[seqn].index]==END)
  528.                         {
  529.                         done=1;
  530.                         perffunc(seqn);
  531.                         }
  532.                     break;
  533.                 case ASCDECCOL:
  534.                     if((c>='0')&&(c<='9'))
  535.                         {
  536.                         ok=1;
  537.                         funcstor[seqn].column*=10;
  538.                         funcstor[seqn].column+=(c-'0');
  539.                         funcstor[seqn].colset=1;
  540.                         }
  541.                     else
  542.                         if(funcstor[seqn].colset&&(c==emu.funcs[seqn].codes[++funcstor[seqn].index]))
  543.                             {
  544.                             ok=1;
  545.                             if(emu.funcs[seqn].codes[++funcstor[seqn].index]==END)
  546.                                 {
  547.                                 done=1;
  548.                                 perffunc(seqn);
  549.                                 }
  550.                             }
  551.                         else
  552.                             clrfuncstor(seqn);
  553.                     break;
  554.                 case ASCDECROW:
  555.                     if((c>='0')&&(c<='9'))
  556.                         {
  557.                         ok=1;
  558.                         funcstor[seqn].row*=10;
  559.                         funcstor[seqn].row+=(c-'0');
  560.                         funcstor[seqn].rowset=1;
  561.                         }
  562.                     else
  563.                         if(funcstor[seqn].rowset&&(c==emu.funcs[seqn].codes[++funcstor[seqn].index]))
  564.                             {
  565.                             ok=1;
  566.                             if(emu.funcs[seqn].codes[++funcstor[seqn].index]==END)
  567.                                 {
  568.                                 done=1;
  569.                                 perffunc(seqn);
  570.                                 }
  571.                             }
  572.                         else
  573.                             clrfuncstor(seqn);
  574.                     break;
  575.                 case ASCDECSEMILIST:
  576.                     if((c>='0')&&(c<='9'))
  577.                         {
  578.                         ok=1;
  579.                         funcstor[seqn].list[funcstor[seqn].listindex]*=10;
  580.                         funcstor[seqn].list[funcstor[seqn].listindex]+=(c-'0');
  581.                         }
  582.                     else
  583.                         {
  584.                         if(funcstor[seqn].listindex<LISTSIZ)
  585.                             funcstor[seqn].listindex++;
  586.                         
  587.                         if(c==';')
  588.                             ok=1;
  589.                         else
  590.                             if(c==emu.funcs[seqn].codes[++funcstor[seqn].index])
  591.                                 {
  592.                                 ok=1;
  593.                                 if(emu.funcs[seqn].codes[++funcstor[seqn].index]==END)
  594.                                     {
  595.                                     done=1;
  596.                                     perffunc(seqn);
  597.                                     }
  598.                                 }
  599.                             else
  600.                                 clrfuncstor(seqn);
  601.                         }
  602.                     break;
  603.                 case GRABCHAR:
  604.                     ok=1;
  605.                     funcstor[seqn].row=c;
  606.                     if(emu.funcs[seqn].codes[++funcstor[seqn].index]==END)
  607.                         {
  608.                         done=1;
  609.                         perffunc(seqn);
  610.                         }
  611.                     break;
  612.                 case GRAPHCHAR_T:
  613.                     if(emu.gchars[c])
  614.                         {
  615.                         ok=1;
  616.                         funcstor[seqn].row=c;
  617.                         if(emu.funcs[seqn].codes[funcstor[seqn].index]==END)
  618.                             {
  619.                             done=1;
  620.                             perffunc(seqn);
  621.                             }
  622.                         }
  623.                     else
  624.                         clrfuncstor(seqn);
  625.                     break;
  626.                 }
  627.         else
  628.             if(c==emu.funcs[seqn].codes[funcstor[seqn].index])
  629.                 {
  630.                 ok=1;
  631.                 if(emu.funcs[seqn].codes[++funcstor[seqn].index]==END)
  632.                     {
  633.                     done=1;
  634.                     perffunc(seqn);
  635.                     }
  636.                 }
  637.             else
  638.                 clrfuncstor(seqn);
  639.         if(done)
  640.             {
  641.             ok=1;
  642.             for(seqn=0;seqn<NFUNCS;seqn++)
  643.                 clrfuncstor(seqn);
  644.             break;
  645.             }
  646.         }
  647.     if(!ok)
  648.         showchar(c);
  649.     }
  650.  
  651. initdisp()
  652.     {
  653.     int i;
  654.     for(i=0;i<NFUNCS;i++)
  655.         {
  656.         funcstor[i].listindex=LISTSIZ;
  657.         clrfuncstor(i);
  658.         }
  659.     bold=faint=blink=inverse=0;
  660.     fgcolor=WHITE;
  661.     bkcolor=BLACK;
  662.     graphics=0;
  663.     wrap_p=emu.default_wrap_p;
  664.     }
  665.  
  666. main(argc, argv)
  667.     int argc;
  668.     char **argv;
  669.     {
  670.     FILE *dribble;
  671.     char c;
  672.     int follow, emufd, i, orun;
  673.     if(!strcmp(getenv("REMOTE"), "YES"))
  674.         {
  675.         printf("You appear to be logged in remotely, judging by the environment\n");
  676.         printf("variable REMOTE, so this is probably a very bad idea.\n");
  677.         printf("Are you sure you want to run TERM? (y or n) --> ");
  678.         if(getchar()!='y') /* Note getchar() and not getch()! */
  679.             {
  680.             printf("I didn't think so!\n");
  681.             exit(99);
  682.             }
  683.         else
  684.             printf("OK, you're the boss!\n");
  685.         }
  686.     _getvideoconfig(vconf);
  687.     index=follow=0;
  688.     if((argc<4)||(argc>6))
  689.         {
  690.         printf("Copyright (C) 1992 Peter Edward Cann, all rights reserved.\n");
  691.         printf("USAGE: term <comnum> <bps> <data><parity><stop> [<emu or - >] [<dribble>]\n");
  692.         printf("<emu> is an emulation file base pathname.\n");
  693.         printf("<dribble> is a dribble (text capture) file.\n");
  694.         printf("The environment variable PCCPPATH is used for the emulation file if set.\n");
  695.         exit(1);
  696.         }
  697.     fpname[0]='\0';
  698.     dribpname[0]='\0';
  699.     if((argc>=5)&&(argv[4][0]=='+'))
  700.         {
  701.         locechop=1;
  702.         argv[4]++;
  703.         }
  704.     else
  705.         locechop=0;
  706.     if((argc>=5)&&(argv[4][0]!='-'))
  707.         {
  708.         if((getenv("PCCPPATH")==NULL)||(argv[4][0]=='\\')||(argv[4][1]==':'))
  709.             sprintf(fpname, "%s.emu", argv[4]);
  710.         else
  711.             sprintf(fpname, "%s\\%s.emu", getenv("PCCPPATH"), argv[4]);
  712.         if((emufd=open(fpname, O_RDONLY|O_BINARY))==-1)
  713.             {
  714.             printf("Error opening emulation file %s.\n", fpname);
  715.             exit(2);
  716.             }
  717.         else
  718.             if(read(emufd, &emu, sizeof(emu))!=sizeof(emu))
  719.                 {
  720.                 printf("Error reading emulation file %s.\n", fpname);
  721.                 exit(3);
  722.                 }
  723.             else;
  724.         }
  725.     else
  726.         {
  727.         nullemu();
  728.         emu.funcs[0].func=LEFT;
  729.         emu.funcs[0].codes[0]='\b';
  730.         emu.funcs[0].codes[1]=END;
  731.         emu.funcs[1].func=DTAB;
  732.         emu.funcs[1].codes[0]='\t';
  733.         emu.funcs[1].codes[1]=END;
  734.         emu.funcs[2].func=BELL;
  735.         emu.funcs[2].codes[0]='\007';
  736.         emu.funcs[2].codes[1]=END;
  737.         }
  738.     if(argc==6)
  739.         {
  740.         strcpy(dribpname, argv[5]);
  741.         if((dribble=fopen(argv[5], "a"))==NULL)
  742.             {
  743.             printf("Couldn't open dribble file %s.\n");
  744.             exit(10);
  745.             }
  746.         else
  747.             fprintf(dribble, "\nBeginning of dribble segment.\n\n");
  748.         }
  749.     else
  750.         dribble=NULL;
  751.     comnum=atoi(argv[1])-1;
  752.     speed=atoi(argv[2]);
  753.     parity=argv[3][1];
  754.     databits=argv[3][0];
  755.     stopbits=argv[3][2];
  756.     setport();
  757.     readset();
  758.     setup();
  759.     _clearscreen(_GCLEARSCREEN);
  760.     initdisp();
  761.     updstatus();
  762.     atthndl();
  763.     _settextposition(1,1);
  764.     orun=0;
  765.     if(vconf->adapter==_VGA)
  766.         _remappalette(8, (long)0x00202020); /* Lighten up gray */
  767.     while(1)
  768.         {
  769.         if((_bios_keybrd(_KEYBRD_SHIFTSTATUS) & 3) == 3)
  770.             {
  771.             cleanup(0);
  772.             _settextcolor(WHITE);
  773.             _setbkcolor((long)BLACK);
  774.             if(dribble!=NULL)
  775.                 {
  776.                 fprintf(dribble, "\nEnd of dribble segment.\n");
  777.                 fclose(dribble);
  778.                 }
  779.             if(vconf->adapter==_VGA)
  780.                 _remappalette(8, _GRAY); /* Restore gray */
  781.             _outtext("\nOrderly exit from TERM.\n");
  782.             exit(0);
  783.             }
  784.         if(_bios_keybrd(_KEYBRD_READY))
  785.             dispkbd(_bios_keybrd(_KEYBRD_READ));
  786.         if(follow!=index)
  787.             {
  788.             if(dribble!=NULL)
  789.                 fputc(buf[follow], dribble);
  790.             /* We only display if we're not too far behind; */
  791.             /* this makes dribble more reliable. */
  792.             if(((index-follow)>4096)||(((index-follow)<0)&&((follow-index)<4096)))
  793.                 if(!orun)
  794.                     {
  795.                     orun=1;
  796.                     initdisp();
  797.                     }
  798.                 else;
  799.             else
  800.                 {
  801.                 orun=0;
  802.                 dispport(buf[follow]);
  803.                 }
  804.             follow++;
  805.             follow=follow%TBUFSIZ;
  806.             }
  807.         }
  808.     }
  809.